package model.dao;

import model.entity.Book;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Connection;
import java.sql.Date;

public class AddDaoImpl implements AddDao{

    private JdbcTemplate template;

    public AddDaoImpl(JdbcTemplate template) {
        this.template =template;
    }

    @Override
    public boolean add(Book book) {

        String bookNo=book.getBookNo();
        String bookName=book.getBookName();
        String press=book.getPress();
        Date pubTime=book.getPubTime();
        String author=book.getAuthor();
        String location=book.getLocation();
        double price=book.getPrice();
        boolean isBorrowed=book.isBorrowed();
        String sql="insert into books values(?,?,?,?,?,?,?,?)";
        int count=template.update(sql,bookNo,bookName,press,pubTime,author,location,price,isBorrowed);
        return count==1?true:false;
    }

    @Test
    public void test()
    {
        Book book=new Book("00","1","1",new Date(1-1-1),"1","1",1,false);
        add(book);
    }
}
